<?php
session_start();
include '../models/Model.php';
$login = TRUE;
$admin=2;
$users=1;
$newuser = 0;
$model=new model();
$AccName=$_POST['tbID'];
$pass=$_POST['tbPassword'];
$user=$model->searchUserAccName($AccName);
if($user->getUserId()){
	if($user->getUserPassword()==$pass){
		$_SESSION['userId']=$user->getUserId();
		$date = date("Y-m-d H:i:s");
		$log = $date."---Event---".$AccName."---Login\n";
		$path="../log/log.txt";
		$file=fopen($path, "a");
		$write=fwrite($file,$log);
		fclose($file);
		if ($user->getUserKind()==$users) header("Location:../view/user/view_room.php");
		else if($user->getUserKind()==$newuser) $login = FALSE;
		else header("Location:../view/manager/admin.php");
	}
	else $login = FALSE;
}
else $login = FALSE;

if ($login==FALSE) {
	header("Location: ../view/user/login.php?login=f");
	session_destroy();	
}	

?>